from asyncio.base_tasks import _task_repr_info
from doctest import FAIL_FAST
import enum
from re import S, X
from matplotlib import widgets
from requests import head
from soupsieve import select

from PIL import Image, ImageDraw

from PIL import Image, ImageQt
# ros
import rclpy
import threading
from rclpy import executors
from rclpy.qos import qos_profile_sensor_data
from std_msgs.msg import String
from std_msgs.msg import Int16 as int16
from sensor_msgs.msg import CompressedImage
from PyQt5 import QtCore, QtGui, QtWidgets
from rv_sensorfusion.msg import ARadarObject, ARadarObjectList, ACameraObject, ACameraObjectList, AObstacle, AObstacleList
# 与嵌入matplotlib绘图必须
import matplotlib
from matplotlib.patches import Ellipse, Circle
import matplotlib.patches as mpatches
import matplotlib.pyplot as plt
matplotlib.use("Qt5Agg")  # 声明使用QT5
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
import numpy as np
# 系统
import os
# pyqt必须
import sys

from types import MethodType
from PyQt5.Qt import *
from PyQt5.QtCore import Qt, QRect, QPropertyAnimation
from PyQt5.QtWidgets import QApplication, QMainWindow, QGridLayout, QTableWidgetItem,QLabel
from PyQt5.QtGui import QMovie
from PyQt5.QtGui import QPalette, QBrush, QPixmap,QImage
from .layout import layout as myui
from PyQt5.Qt import QStandardItemModel,QMutex
from PyQt5.QtGui import QStandardItem
from PyQt5.QtCore import QThread,pyqtSignal
import time
import sip
# 计算
# opencv
import cv2
from cv_bridge import CvBridge
import math
# random
import random as rd



class MyFigure(FigureCanvas):
    def __init__(self, width, height, dpi=100):
        # 第一步：创建一个创建Figure
        self.fig = Figure(figsize=(width, height), dpi=dpi)
        # 第二步：在父类中激活Figure窗口
        super(MyFigure, self).__init__(self.fig)  # 此句必不可少，否则不能显示图形



    
class ThreadTable1(QThread):

    update_data = pyqtSignal() #自定义一个信号
    
    def __init__(self,parent=None,*args,**kwargs):
        super(ThreadTable1, self).__init__(parent,*args,**kwargs)
        
    def run(self):
        
        cnt = 0
        while True:
            cnt += 1
            
            self.update_data.emit()  # 发射信号
            time.sleep(0.1)
            
            
        
    
class ThreadTable2(QThread):
     

    update_data = pyqtSignal() #自定义一个信号
    
    
    def __init__(self,parent=None,*args,**kwargs):
        super(ThreadTable2, self).__init__(parent,*args,**kwargs)

        # self.task_ready =True
        
    # 可在外部与槽函数连接
    def run(self):
        
        cnt = 0
        while True:
            cnt += 1
            self.update_data.emit()  # 发射信号
            
            time.sleep(0.03)

class ThreadTable3(QThread):
     

    update_data = pyqtSignal() #自定义一个信号
    
    
    def __init__(self,parent=None,*args,**kwargs):
        super(ThreadTable3, self).__init__(parent,*args,**kwargs)

        self.task_ready =False
        
    # 可在外部与槽函数连接
    def run(self):
        
        cnt = 0
        while True:
            cnt += 1
            if self.task_ready==True:
                self.update_data3.emit()  # 发射信号
                self.task_ready=False
                time.sleep(0.05)
            
        


class MyQLabel(QtWidgets.QLabel):
    # 自定义信号, 注意信号必须为类属性
    button_clicked_signal = QtCore.pyqtSignal()
    isClicked = False
    def __init__(self, parent=None):
        super(MyQLabel, self).__init__(parent)
        
    def mouseReleaseEvent(self, QMouseEvent):
        self.button_clicked_signal.emit()
        self.isClicked = True
        
    # 可在外部与槽函数连接
    def connect_customized_slot(self, func):
        self.button_clicked_signal.connect(func)


class Ui_MainWindow_add_logic(myui.Ui_MainWindow):


    # ----------------------------------初始化窗口-----------------------------------
    def __init__(self,MainWindow):
        
        # -----------------------------继承节目布局-----------------------------------
        super(Ui_MainWindow_add_logic,self).setupUi(MainWindow)
        self.MainWindow = MainWindow
        self.MainWindow.showFullScreen()
        #-------------------------------------------
        
        self.node_init()
        self.thread_init(MainWindow)
        self.flag_init()
        self.resource_init()
        self.window_init(MainWindow)
        
        self.style_init()
        self.slot_init()



    # -----------------------------风格初始化------------------------------------
    def style_init(self):
        
        # 初值
        self.scrollnum = 0
        # 滑动区域
        self.scrollAreaWidgetContents.setStyleSheet("background-color:transparent;")
        self.scrollArea.setStyleSheet("background-color:transparent;")
        self.scrollBar = self.scrollArea.horizontalScrollBar()
        w = self.scrollAreaWidgetContents.width()
        ww = int(w/8)
        # label

        # 设置背景颜色，包括边框颜色
        self.label.setStyleSheet("border:none")
        self.label_11.setStyleSheet("border:none")
        self.label_12.setStyleSheet("border:none")
        self.scrollBar.setValue(ww*self.select)
        self.label_13.setPixmap(QtGui.QPixmap(self.bar))
        self.label_14.setPixmap(QtGui.QPixmap(self.bar))
        self.label_15.setStyleSheet("color:White")
        self.label_16.setStyleSheet("color:White")

        self.label_17.setStyleSheet("color:White")
        self.label_17.setPixmap(QtGui.QPixmap(self.recording_video_txtlabel))
        self.label_18.setStyleSheet("color:White")
        self.label_18.setPixmap(QtGui.QPixmap(self.left_video_txtlabel))
        self.label_19.setStyleSheet("color:White")
        self.label_19.setPixmap(QtGui.QPixmap(self.right_video_txtlabel))
        

        self.label_24.setPixmap(QtGui.QPixmap(self.scrollArea_p))
        self.label_24.lower()
        self.png_arrow = QPixmap(self.arrow_p)
        # self.label_24.setPixmap(self.png_arrow)
        
        # 按钮样式

        # 天气显示区域

        for i,label in enumerate(self.weather_labels):
            print("self.select",self.select)
            print("self.old_select",self.old_select)
            if self.select==i+1:
                
                # 设置边框样式 可选样式有Box Panel等

                label.setFrameShape(QtWidgets.QFrame.Box)
                # 设置阴影 只有加了这步才能设置边框颜色 
                # 可选样式有Raised、Sunken、Plain（这个无法设置颜色）等
                label.setFrameShadow(QtWidgets.QFrame.Raised)
                # 设置线条宽度
                label.setLineWidth(5)
                # 设置背景颜色，包括边框颜色
                label.setStyleSheet("background-color:transparent;")
                self.label_pic = self.weather_s_paths[i]
                label.setPixmap(QtGui.QPixmap( self.label_pic))
                label.setScaledContents(True)
            elif self.select==0:
                # text
                self.label_15.setStyleSheet("color:White")
                self.label_16.setStyleSheet("color:White")
                self.label_15.setText("实况")
                self.label_16.setText("实况")

                # 设置边框样式 可选样式有Box Panel等
                label.setFrameShape(QtWidgets.QFrame.Box)
                # 设置阴影 只有加了这步才能设置边框颜色 
                # 可选样式有Raised、Sunken、Plain（这个无法设置颜色）等
                label.setFrameShadow(QtWidgets.QFrame.Raised)
                # 设置线条宽度
                label.setLineWidth(5)
                # 设置背景颜色，包括边框颜色
                label.setStyleSheet("background-color:transparent;")
                self.label_pic = self.weather_paths[i]
                label.setPixmap(QtGui.QPixmap( self.label_pic))
                label.setScaledContents(True)
            else:
                
                # 设置边框样式 可选样式有Box Panel等
                label.setFrameShape(QtWidgets.QFrame.Box)
                # 设置阴影 只有加了这步才能设置边框颜色 
                # 可选样式有Raised、Sunken、Plain（这个无法设置颜色）等
                label.setFrameShadow(QtWidgets.QFrame.Raised)
                # 设置线条宽度
                label.setLineWidth(5)
                # 设置背景颜色，包括边框颜色
                label.setStyleSheet("background-color:transparent;")
                self.label_pic = self.weather_paths[i]
                label.setPixmap(QtGui.QPixmap( self.label_pic))
                label.setScaledContents(True)
            

        
        
        # # 左键盘
        # icon1 = QtGui.QIcon()
        # icon1.addPixmap(QtGui.QPixmap(self.lb_unclicked), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        # self.pushButton.setIcon(icon1)
        # self.pushButton.setStyleSheet("background-color:rgb(61, 70, 82);")
        # self.pushButton.setStyleSheet("border:none;")
        # self.pushButton.setIconSize(QtCore.QSize(100, 100))
        # # op = QtWidgets.QGraphicsOpacityEffect()
        # # # 设置透明度的值，0.0到1.0，最小值0是透明，1是不透明
        # # op.setOpacity(0.5)
        # # self.pushButton.setGraphicsEffect(op)
        

        # # 右键盘
        # icon2 = QtGui.QIcon()
        # icon2.addPixmap(QtGui.QPixmap(self.rb_clicked), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        # self.pushButton_2.setIcon(icon2)
        # self.pushButton_2.setIconSize(QtCore.QSize(100, 100))
        # self.pushButton_2.setStyleSheet("background-color:rgb(61, 70, 82);")
        # self.pushButton_2.setStyleSheet("border:none;")
        # # op = QtWidgets.QGraphicsOpacityEffect()
        # # # 设置透明度的值，0.0到1.0，最小值0是透明，1是不透明
        # # op.setOpacity(0.5)
        # # self.pushButton_2.setGraphicsEffect(op)

        # 暂停/播放
        if self.select!=-1:
            # self.movie = QMovie(self.pause_button)
            # self.label_7.setMovie(self.movie)
            # self.movie.start()
            # # self.label_7.resize(200,200)
            self.label_7.setPixmap(QtGui.QPixmap(self.pause_P))
            self.label_7.setScaledContents(True)
        elif self.select==1:
            # self.movie = QMovie(self.play_button)
            # self.label_7.setMovie(self.movie)
            # self.movie.start()
            # # self.label_7.resize(200,200)
            self.label_7.setPixmap(QtGui.QPixmap(self.play_P))
            self.label_7.setScaledContents(True)

    def pause_update(self):
        # 暂停/播放
        if self.select!=-1:
            self.label_7.setPixmap(QtGui.QPixmap(self.pause_P))
            self.label_7.setScaledContents(True)
            self.label_7.setScaledContents(True)
        elif self.select==-1:
            self.label_7.setPixmap(QtGui.QPixmap(self.play_P))
            self.label_7.setScaledContents(True)
            self.label_7.setScaledContents(True)

    def weather_update(self):
        print("select:",self.select)
        print("scrollnum:",self.scrollnum)
        print("slide:",self.slide_mode)
        if self.slide_mode==0:
            if self.select>4:
                self.scrollnum=1
            elif self.select==-1:
                pass
            else:
                self.scrollnum=0

            w = self.scrollAreaWidgetContents.width()
            self.scrollBar.setValue(int(w*self.scrollnum))


        # 按钮样式
        # 天气显示区域
        self.label_13.setPixmap(QtGui.QPixmap(self.bar))
        self.label_14.setPixmap(QtGui.QPixmap(self.bar))
        for i,label in enumerate(self.weather_labels):
            print("self.select",self.select)
            if self.select==i+1:
                label.setStyleSheet("color:White")
                # 设置边框样式 可选样式有Box Panel等
                label.setFrameShape(QtWidgets.QFrame.Box)
                # 设置阴影 只有加了这步才能设置边框颜色 
                # 可选样式有Raised、Sunken、Plain（这个无法设置颜色）等
                label.setFrameShadow(QtWidgets.QFrame.Raised)
                # 设置线条宽度
                label.setLineWidth(5)
                # 设置背景颜色，包括边#视频3框颜色
                label.setStyleSheet("background-color:transparent;")
                self.label_pic = self.weather_s_paths[i]
                label.setPixmap(QtGui.QPixmap( self.label_pic))
                label.setScaledContents(True)

                # text
                self.label_15.setStyleSheet("color:White")
                self.label_16.setStyleSheet("color:White")
                self.label_15.setText(self.weather_text[i])
                self.label_16.setText(self.weather_text[i])
            elif self.select==0:
                # text
                self.label_15.setStyleSheet("color:White")
                self.label_16.setStyleSheet("color:White")
                self.label_15.setText("实况")
                self.label_16.setText("实况")

                # 设置边框样式 可选样式有Box Panel等
                label.setFrameShape(QtWidgets.QFrame.Box)
                # 设置阴影 只有加了这步才能设置边框颜色 
                # 可选样式有Raised、Sunken、Plain（这个无法设置颜色）等
                label.setFrameShadow(QtWidgets.QFrame.Raised)
                # 设置线条宽度
                label.setLineWidth(5)
                # 设置背景颜色，包括边框颜色
                label.setStyleSheet("background-color:transparent;")
                self.label_pic = self.weather_paths[i]
                label.setPixmap(QtGui.QPixmap( self.label_pic))
                label.setScaledContents(True)
            else:
                
                # 设置边框样式 可选样式有Box Panel等
                label.setFrameShape(QtWidgets.QFrame.Box)
                # 设置阴影 只有加了这步才能设置边框颜色 
                # 可选样式有Raised、Sunken、Plain（这个无法设置颜色）等
                label.setFrameShadow(QtWidgets.QFrame.Raised)
                # 设置线条宽度
                label.setLineWidth(5)
                # 设置背景颜色，包括边框颜色
                label.setStyleSheet("background-color:transparent;")
                self.label_pic = self.weather_paths[i]
                label.setPixmap(QtGui.QPixmap( self.label_pic))
                label.setScaledContents(True)

        
        
        


    # ------------------------------槽函数配置-----------------------------------
    def slot_init(self):
        pass
        # # 按钮
        # self.pushButton.clicked.connect(self.home)
        

        self.label_7.mousePressEvent = self.photo_link_pause
        self.label.mousePressEvent = self.photo_link_camera

        self.label_2.mousePressEvent = self.photo_link_w1
        self.label_3.mousePressEvent = self.photo_link_w2
        self.label_4.mousePressEvent = self.photo_link_w3
        self.label_5.mousePressEvent = self.photo_link_w4

        self.label_6.mousePressEvent = self.photo_link_w5
        self.label_8.mousePressEvent = self.photo_link_w6
        self.label_9.mousePressEvent = self.photo_link_w7
        self.label_10.mousePressEvent = self.photo_link_w8



    def resource_init(self):

        # ------------------------------文件路径-------------------------------------
        
        # 设置根路径
        self.pix_P = 'src/mot_ui/mot_ui/submodules/gif'
        self.pix_P = 'src/mot_ui/mot_ui/submodules/gif'
        self.pix_ui = 'src/mot_ui/mot_ui/submodules/ui'
        self.cv_img = 'src/mot_ui/mot_ui/submodules'
        # 箭头
        self.arrow_p = 'src/mot_ui/resource/arrow.png'
        # 天气图标
        self.weather_text = ["晴天正午", "晴天傍晚", "晴天晚上", "雨天正午", "雨天傍晚", "雨天晚上", "停车场１", "停车场２"]
        self.weathers_p = 'src/mot_ui/resource/weather'
        self.weathers_s_p = 'src/mot_ui/resource/s_weather'
        # 按钮
        self.left_button = 'src/mot_ui/resource/chevron-left.svg'
        self.right_button = 'src/mot_ui/resource/chevron-right.svg'
        self.play_button = 'src/mot_ui/resource/play_pause/pause.gif'
        self.pause_button = 'src/mot_ui/resource/play_pause/play.gif'
        # 滑动区域
        self.scrollArea_p = 'src/mot_ui/mot_ui/submodules/ui/scroll_area.png'
        # 图像标签
        self.left_video_txtlabel = 'src/mot_ui/mot_ui/submodules/ui/pe.png'
        self.right_video_txtlabel = 'src/mot_ui/mot_ui/submodules/ui/ae.png'
        self.recording_video_txtlabel = 'src/mot_ui/mot_ui/submodules/ui/recording.png'
        # bar
        self.bar = 'src/mot_ui/mot_ui/submodules/ui/bar.png'
        # 左右键
        
        self.lb_clicked = 'src/mot_ui/mot_ui/submodules/ui/l_clicked.png'
        self.lb_unclicked = 'src/mot_ui/mot_ui/submodules/ui/l_unclicked.png'
        
        self.rb_clicked = 'src/mot_ui/mot_ui/submodules/ui/r_clicked.png'
        self.rb_unclicked ='src/mot_ui/mot_ui/submodules/ui/r_unclicked.png'
        # 播放键
        self.play_P = 'src/mot_ui/mot_ui/submodules/ui/play.png'
        self.pause_P = 'src/mot_ui/mot_ui/submodules/ui/pause.png'
        # 文件名
        self.weather = os.listdir(self.weathers_p)
        self.weather_s = os.listdir(self.weathers_s_p)
        self.files = os.listdir(self.pix_P)
        self.uipgs = os.listdir(self.pix_ui)
        self.weather.sort(key=lambda x: int(x.split('.')[0]))
        self.weather_s.sort(key=lambda x: int(x.split('.')[0]))
        # 文件路径
        self.weather_paths = [os.path.join(self.weathers_p,file) for file in self.weather]
        self.weather_s_paths = [os.path.join(self.weathers_s_p,file) for file in self.weather_s]
        self.paths = [os.path.join(self.pix_P,file) for file in self.files]
        self.uipgpaths = [os.path.join(self.pix_ui,file) for file in self.uipgs]

        # 空间组
        #2,3,4,5,6,8,9,10
        self.weather_labels = [self.label_2,self.label_3,self.label_4,self.label_5,self.label_6,self.label_8,self.label_9,self.label_10]
    # ------------------------------窗口初始化-------------------------------------
    def window_init(self,MainWindow):
        
        # 分辨率
        self.desktop = QApplication.desktop()
        self.screenRect = self.desktop.screenGeometry()
        self.screenheight = self.screenRect.height()
        self.screenwidth = self.screenRect.width()
        self.window = MainWindow
        MainWindow.setMinimumSize(200, 200)
        MainWindow.setMaximumSize(self.screenwidth, self.screenheight)
        # MainWindow.setWindowFlag(QtCore.Qt.FramelessWindowHint)  # 无边框
        MainWindow.setAutoFillBackground(True) #一定要加上
        # MainWindow.setAttribute(QtCore.Qt.WA_TranslucentBackground)  # 窗口透明
        MainWindow.resize(1920,1080)
        MainWindow.setStyleSheet("#MainWindow{border-image:url(src/mot_ui/mot_ui/submodules/ui/bk.png)}") # 设置背景图片
        # 全屏选项
        # MainWindow.showFullScreen()
    # ------------------------------标志位初始化-----------------------------------
    # 计数器
    def flag_init(self):

        self.cnt = 0
        
        # 暂停/播放 标志位
        self.pause=0

        # 任务状态
        self.index = 0
        
        # 选项
        self.select = 0
        self.old_select = 0
        # 数据刷新
        self.olddata=0
        # 选择模式
        self.slide_mode = 0
        
    # -----------------------------------线程管理--------------------------------------
    def thread_init(self,MainWindow):

        # 1.启动节点线程
        self.executor_thread = threading.Thread(
        target=self.executor.spin, daemon=True)
        self.executor_thread.start()
        # 2.任务1：video1
        self.video1_thread = ThreadTable2() #实例化子线程
        self.video1_thread.start() #启动线程
        self.video1_thread.update_data.connect(self.video_play1) #将子线程信号连接到槽就可以了
        # 3.任务2：video2
        self.video2_thread = ThreadTable2() #实例化子线程
        self.video2_thread.start() #启动线程
        self.video2_thread.update_data.connect(self.video_play2) #将子线程信号连接到
        # 3.任务3：video3
        self.video3_thread = ThreadTable2() #实例化子线程
        self.video3_thread.start() #启动线程
        self.video3_thread.update_data.connect(self.video_play3) #将子线程信号连接到
        
        # 3.任务4：监听滑动事件
        self.event_thread = ThreadTable1() #实例化子线程
        self.event_thread.start() #启动线程
        self.event_thread.update_data.connect(self.slide) #将子线程信号连接到


        # # 待定
        # self.ani_thread = ThreadTable3() #实例化子线程
        # self.ani_thread.start() #启动线程
        # self.ani_thread.update_data3.connect(self.label_change) #将子线程信号连接到
        # # self.draw_thread.update_data2.connect(self.graph) #将子线程信号连接到槽就可以了


    # -----------------------------------节点管理--------------------------------------

    # 节点初始化
    def node_init(self):

        # 1.创建节点
        self.sub = rclpy.create_node("data")
        
        # 2.创建并初始化订阅者成员属性
        self.sub_img1 = self.sub.create_subscription(CompressedImage,"/driver/camera/image_raw/compressed",self.recv_img1_callback,10)
        self.sub_img2 = self.sub.create_subscription(CompressedImage,"/image_handled/compressed",self.recv_img2_callback,10)
        self.sub_img3 = self.sub.create_subscription(CompressedImage,"/driver/camera/image_raw_small/compressed",self.recv_img3_callback,10)
        
        # 3.创建并初始化发布者成员属性
        self.pub1 = self.sub.create_publisher(int16,"/select_topic", 10)

        # 4.周期监听发布者内容选项变更
        self.timer = self.sub.create_timer(0.1, self.timer_callback)
        
        # 5.添加要启动节点
        self.executor = executors.MultiThreadedExecutor()
        self.executor.add_node(self.sub)
    
    # -----------------------------------槽函数--------------------------------------
    def photo_link_camera(self,n):
        print("you press label camera")
        if self.MainWindow.select_flag:
            self.select=0
            self.old_select=0
            self.pause_update()
            self.weather_update()
    def photo_link_w1(self,n):
        if self.MainWindow.select_flag:
            print("you press label w1")
            self.select=1
            self.old_select=1
            self.pause_update()
            self.weather_update()
    def photo_link_w2(self,n):
        print("you press label w2")
        if self.MainWindow.select_flag:
            self.select=2
            self.old_select=2
            self.pause_update()
            self.weather_update()
    def photo_link_w3(self,n):
        print("you press label w3")
        if self.MainWindow.select_flag:
            self.select=3
            self.old_select=3
            self.pause_update()
            self.weather_update()
    def photo_link_w4(self,n):
        print("you press label w4")
        if self.MainWindow.select_flag:
            self.select=4
            self.old_select=4
            self.pause_update()
            self.weather_update()
    def photo_link_w5(self,n):
        print("you press label w5")
        if self.MainWindow.select_flag:
            self.select=5
            self.old_select=5
            self.pause_update()
            self.weather_update()
    def photo_link_w6(self,n):
        print("you press label w6")
        if self.MainWindow.select_flag:
            self.select=6
            self.old_select=6
            self.pause_update()
            self.weather_update()
    def photo_link_w7(self,n):
        print("you press label w7")
        if self.MainWindow.select_flag:
            self.select=7
            self.old_select=7
            self.pause_update()
            self.weather_update()
    def photo_link_w8(self,n):
        print("you press label w8")
        if self.MainWindow.select_flag:
            self.select=8
            self.old_select=8
            self.pause_update()
            self.weather_update()                            
    def photo_link_pause(self,n):
        
        # 槽函数尽量不做实现，而是改变标志位，把耗时工作放在线程里
        # 只有一个播放键label故不需要mylabel类
        

        
        if self.select==-1:
            # 播放
            # print("you press label play")
         
            self.select = self.old_select
            self.pause_update()
            
        else:
            # 暂停
            # print("you press label pause")
   
            self.old_select = self.select
            self.select=-1
            self.pause_update()
            print("you press label pause")
        
        # 播放
        pass
        # 切换动画
        pass

    def button_left(self):

        # 左浏览键
        print("点击左键")
        self.slide_mode = 0
        # 按一次左移动一次
        if self.select==-1:
            self.select=self.old_select
            

        self.select-=1

        if self.select>0:
            self.pause_update()
            self.weather_update()
        if self.select==0:

            self.select=1

            icon1 = QtGui.QIcon()
            icon2 = QtGui.QIcon()
            
            
            icon2.addPixmap(QtGui.QPixmap(self.rb_clicked), QtGui.QIcon.Normal, QtGui.QIcon.Off)
            icon1.addPixmap(QtGui.QPixmap(self.lb_unclicked), QtGui.QIcon.Normal, QtGui.QIcon.Off)

            self.pushButton.setIcon(icon1)
            self.pushButton_2.setIcon(icon2)
            

    def button_right(self):
        print("点击右键")
        self.slide_mode = 0
        if self.select==-1:
            self.select=self.old_select
            
        self.select+=1
            
        if self.select<=8:
            self.pause_update()
            self.weather_update()
        
        if self.select==9:

            self.select=8
            icon1 = QtGui.QIcon()
            icon2 = QtGui.QIcon()
            
            
            icon2.addPixmap(QtGui.QPixmap(self.rb_unclicked), QtGui.QIcon.Normal, QtGui.QIcon.Off)
            icon1.addPixmap(QtGui.QPixmap(self.lb_clicked), QtGui.QIcon.Normal, QtGui.QIcon.Off)

            self.pushButton.setIcon(icon1)
            self.pushButton_2.setIcon(icon2)


    def slide(self):

        if self.MainWindow.drag_x>0:

            self.slide_mode = 1
        # 实现空间滑动
        self.scrollBar = self.scrollArea.horizontalScrollBar()
        v = self.scrollBar.value()
        # print(v)
        # print(self.MainWindow.drag_x)
        
        self.scrollBar.setValue(v-self.MainWindow.drag_x * 10)
        

    def button_pause(self):

        # 暂停键
        print("pause change")

        if self.select!=-1:
            self.select=-1
            icon1 = QtGui.QIcon()
            icon1.addPixmap(QtGui.QPixmap("src/mot_ui/resource/play-outline.svg"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
            self.pushButton_2.setIcon(icon1)
            self.pushButton_2.setIconSize(QtCore.QSize(100, 40))
            self.pushButton_2.resize(100, 40)
            print("pause=1")
        else:
            icon1 = QtGui.QIcon()
            icon1.addPixmap(QtGui.QPixmap("src/mot_ui/resource/pause-outline.svg"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
            self.pushButton_2.setIcon(icon1)
            self.pushButton_2.setIconSize(QtCore.QSize(100, 40))
            self.pushButton_2.resize(100, 40)
            
    
    # -------------------------------------------------------------------------------线程1---------------------------------------------------------------
  
    # -------------------------------------------callback_func------------------
    def video_play1(self):

        # width = self.label_11.width()  ##获取图片宽度
        # height = self.label_11.height() ##获取图片高度
        # self.png1 = self.png1.scaled(width*2, height*2)##调整图片尺寸
        # self.png3 = self.png3.scaled(width*2, height*2)##调整图片尺寸
        # new_img1 = new_img1.scaledToWidth(width*3)
                    
        self.label_11.setPixmap(self.png1)


    def video_play2(self):

                    
        self.label_12.setPixmap(self.png2)

            
        # width = self.png2.width()  ##获取图片宽度
        # height = self.png2.height() ##获取图片高度
        # new_img2 = self.png2.scaled(width*3, height*3)##调整图片尺寸
        # new_img2 = new_img2.scaledToWidth(width*3)
        

    def video_play3(self):


        # width = self.png3.width()  ##获取图片宽度
        # height = self.png3.height() ##获取图片高度
        # new_img3 = self.png3.scaled(width*3, height*3)##调整图片尺寸
        # new_img3 = new_img3.scaledToWidth(width*3)

        self.label.setPixmap(self.png3)



                

    def recv_img1_callback(self,msg):


        # print("receive msg")
        bridge = CvBridge()
        # 压缩图像转化为cv图像
        cv_image = bridge.compressed_imgmsg_to_cv2(msg, "bgr8")
        RGBImg = cv2.cvtColor(cv_image, cv2.COLOR_BGR2RGB)
        # CV图像转化为Image图像
        Image_img = Image.fromarray(RGBImg)
        # Image图像作圆角处理
        Image_corner = self.picture_corner(Image_img,15)
        # 转化为QImage
        Pix_corner = ImageQt.ImageQt(Image_corner)
        # 转化为PixImage
        self.png1 = QPixmap.fromImage(Pix_corner)
        
    
    def recv_img2_callback(self,msg):


        # print("receive msg")
        bridge = CvBridge()
        # 压缩图像转化为cv图像
        cv_image = bridge.compressed_imgmsg_to_cv2(msg, "bgr8")
        RGBImg = cv2.cvtColor(cv_image, cv2.COLOR_BGR2RGB)
        # CV图像转化为Image图像
        Image_img = Image.fromarray(RGBImg)
        # Image图像作圆角处理
        Image_corner = self.picture_corner(Image_img,15)
        # 转化为QImage
        Pix_corner = ImageQt.ImageQt(Image_corner)
        self.png2 = QPixmap.fromImage(Pix_corner)
    
    def recv_img3_callback(self,msg):


        # print("receive msg")
        bridge = CvBridge()
        # 压缩图像转化为cv图像
        cv_image = bridge.compressed_imgmsg_to_cv2(msg, "bgr8")
        RGBImg = cv2.cvtColor(cv_image, cv2.COLOR_BGR2RGB)
        # CV图像转化为Image图像
        Image_img = Image.fromarray(RGBImg)
        # Image图像作圆角处理
        Image_corner = self.picture_corner(Image_img,15)
        # 转化为QImage
        Pix_corner = ImageQt.ImageQt(Image_corner)
        self.png3 = QPixmap.fromImage(Pix_corner)
    def timer_callback(self):

        msg = int16()

        msg.data = self.select

     
        print("select = ",self.select)
        if self.olddata!=msg.data:
            self.pub1.publish(msg) 

            self.olddata = msg.data
            self.sub.get_logger().info(f'发布了指令：{msg.data}')    #打印一下发布的数据

    
    def picture_corner(self, img, radii):
        circle = Image.new('L', (radii * 2, radii * 2), 0)  # 创建黑色方形
        draw = ImageDraw.Draw(circle)
        draw.ellipse((0, 0, radii * 2, radii * 2), fill=255)  # 黑色方形内切白色圆形

        img = img.convert("RGBA")
        w, h = img.size

        #创建一个alpha层，存放四个圆角，使用透明度切除圆角外的图片
        alpha = Image.new('L', img.size, 255)
        alpha.paste(circle.crop((0, 0, radii, radii)), (0, 0))  # 左上角
        alpha.paste(circle.crop((radii, 0, radii * 2, radii)),
                    (w - radii, 0))  # 右上角
        alpha.paste(circle.crop((radii, radii, radii * 2, radii * 2)),
                    (w - radii, h - radii))  # 右下角
        alpha.paste(circle.crop((0, radii, radii, radii * 2)),
                    (0, h - radii))  # 左下角
        img.putalpha(alpha)  # 白色区域透明可见，黑色区域不可见
        
        return img

    
